#define _WIN32_WINNT 0x500
#include "Canvas.hpp"
#include <stdexcept>

using namespace std;

Canvas::Canvas( HDC hdc )
	: hdc( hdc )
{
}

void Canvas::drawRectangle( int left, int top, int right, int bottom, COLORREF lineColor, COLORREF fillColor )
{
	if (hdc == 0)
		throw logic_error( "Only call DrawRectangle from the Paint method" );
	SetDCPenColor( hdc, lineColor );
	SetDCBrushColor( hdc, fillColor );
	Rectangle( hdc, left, top, right + 1, bottom + 1 );
}

void Canvas::drawEllipse( POINT center, unsigned int radius, COLORREF lineColor, COLORREF fillColor )
{
	if (hdc == 0)
		throw logic_error( "Only call DrawEllipse from the Paint method" );
	SetDCPenColor( hdc, lineColor );
	SetDCBrushColor( hdc, fillColor );
	Ellipse( hdc, center.x - radius, center.y - radius, center.x + radius + 1, center.y + radius + 1 );
}

void Canvas::drawTriangle( POINT a, POINT b, POINT c, COLORREF lineColor, COLORREF fillColor )
{
	if (hdc == 0)
		throw logic_error( "Only call DrawTriangle from the Paint method" );
	POINT triangle[3]= {a, b, c};
	SetDCPenColor( hdc, lineColor );
	SetDCBrushColor( hdc, fillColor );
	Polygon( hdc, triangle, 3 );
}

void Canvas::drawPolygon( POINT points[], int size, COLORREF lineColor, COLORREF fillColor )
{
	if (hdc == 0)
		throw logic_error( "Only call DrawPolygon from the Paint method" );
	SetDCPenColor( hdc, lineColor );
	SetDCBrushColor( hdc, fillColor );
	Polygon( hdc, points, size );
}
